/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinAviSub.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinAviSubEvent.h"

INT32S WinAviSubMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinAviSubOnShow(hwnd, lpParam) ;
        case WM_HIDEWINDOW:
            return WinAviSubOnHide(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinAviSubPalette(void)
{
    YUVENTRY mask_para[4] = {0,4095,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinAviSubPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
	case OsdSize720p:	
       case OsdSize1080p:		
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
#endif
            RECT NormalWindowRect = {0,400,700,70};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,400,700,70},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_16,0,0,0},    SetWinAviSubPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinAviSub(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:	
	case OsdSize720p:	
       case OsdSize1080p:		
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
#endif
            CREATEWINDOWPARAM Normalwindow_para = {1,{{0,400,700,70},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_16,0,0,0},SetWinAviSubPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinAviSub",WS_OVERLAPPEDWINDOW,
		                      0,400,700,70,NULL, (INT32S)&Normalwindow_para,WinAviSubMsgProc) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetAviSubCtlPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:
	case OsdSize720p:	
       case OsdSize1080p:		
            pControl->winrect.top = pControl->parent->winrect.top + 48;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 700;
            pControl->winrect.height = 70;
            pControl->draw_info_num = 2;
            RECT DrawRect576i[2] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 4,700,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 38,700,30},
            };
            for(iLoop=0; iLoop < 2; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect576i[iLoop], sizeof(RECT));
            break ;
			
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
#endif
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 700;
            pControl->winrect.height = 70;
            pControl->draw_info_num = 2;
            RECT NormalDrawRect[2] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 4,700,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 38,700,30},
            };
            for(iLoop=0; iLoop < 2; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S AviSubCtlMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return AviSubCtlOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlAviSubCtl(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- AviSubCtl
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
	case OsdSize720p:	
       case OsdSize1080p:		
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
#endif
            pNewControl = AWCreateWinControl("TControl","AviSubCtl",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,700,70,pParent,0,AviSubCtlMsgProc) ;
            pNewControl->win_id = 2 ;
            pNewControl->draw_info_num = 2;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[2] = {
                          {0,0,0,0,(INT32U)sub_txt_line1,DT_STRING_DATA},
                          {0,0,0,0,(INT32U)sub_txt_line2,DT_STRING_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinAviSub(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinAviSub = CreateControlWinAviSub(NULL,CurrentOsdSize);
    SetWinAviSubPos(pWinAviSub,CurrentOsdSize);

    pNewControl= CreateControlAviSubCtl(pWinAviSub,CurrentOsdSize);
    SetAviSubCtlPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinAviSub;
    pWin->pFocusControl = AWFindWinCtrlByName("AviSubCtl");
    return pWinAviSub;
}

void WinResetWinAviSubControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinAviSub
            SetWinAviSubPos(pControl,CurOsdSize) ;
            break ;
        case 2://AviSubCtl
            SetAviSubCtlPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinAviSubPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinAviSub");
    if(pControl == NULL) return ;

    WinResetWinAviSubControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinAviSubPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}
